<template>
	<view class="applet">
		<view class="top">
			<view class="left">
				3月20日 周三
			</view>
			<view class="right">
				农历二月十一
			</view>
		</view>
		<view class="group">
			<view :class="currentindex==index? 'group-1 active' : 'group-1'" v-for="(item,index) in array1"
				@click="active(index)" :key="index">
				<view class="top">
					<view class="left">
						{{item.date}}<!-- {{item.week}} -->
					</view>
					<!-- <view class="right">
						{{item.ldate}}
					</view> -->
				</view>
				<view class="main">
					<view class="txt">
						{{item.txt}}
						<button @click="remove(item.id)">删除</button>
					</view>
					<view class="time">
						<text class="start">{{item.begantime}}</text>
						<text class="end">{{item.endtime}}</text>
					</view>
				</view>
			</view>
		</view>
		<view class="new">
			<navigator url="/pages/schedule/new-schedule/new-schedule">+</navigator>
		</view>
	</view>
	</view>
</template>

<script>
	import axios from 'axios'
	export default {
		data() {
			return {
				array1: [],
				currentindex: 0,
			}
		},
		methods: {
			active(i) {

				if (this.currentindex == i) {
					return
				}
				this.currentindex = i
			},
			remove(id) {
				uni.request({
					url: 'http://localhost:3000/posts/' + id, //请求后端的接口地址,我这个仅供参考
					method: 'DELETE', //这个是后端你请求的方式，是什么请求就使用什么请求方式，且必须大写
					data: {
						txt: "",
						date: "",
						begantime: "",
						endtime: "",
					},
					header: {
						'Content-Type': "application/json", //请求头信息
						'Content-Language': "zh-CN",
						'Accept-Language': "zh-CN",
					},
					success: (res) => { //如果访问接口成功就会进入success
						console.log("接口调用成功");
					},
					fail: () => { //如果访问接口失败就会进入fail

						console.log("err")

					}
				})

			}
		},

		mounted() {
			// this.$axios({
			// 	method: 'get',
			// 	url: 'http://localhost:3000/posts',
			// 	params: {

			// 	}
			// }).then(res => {
			// 	this.array1 = res.data;
			// }, err => {
			// 	console.log(err);
			// })
			//登录

			uni.request({
				url: 'http://localhost:3000/posts', //请求后端的接口地址,我这个仅供参考
				method: 'GET', //这个是后端你请求的方式，是什么请求就使用什么请求方式，且必须大写
				data: {

				},
				header: {
					"Content-Type": "application/json" //请求头信息
				},
				success: (res) => { //如果访问接口成功就会进入success
					console.log("接口调用成功")
					this.array1 = res.data;
				},
				fail: () => { //如果访问接口失败就会进入fail

					console.log("调用接口失败")

				}
			})

		},

	}
</script>

<style lang="less">
	* {
		padding: 0;
		margin: 0;
		box-sizing: border-box;
	}

	a {
		text-decoration: none;
	}

	.applet {
		width: 100%;
		height: 100%;
		background-color: #f1f2f6;
		position: relative;
		padding-bottom: 10px;

		.top {
			display: flex;
			justify-content: space-between;
			color: #6e6f73;
			font-size: 16px;
			font-weight: 400;
			border-bottom: 1px solid #d5d6da;
			padding: 25px 30px 10px;
		}

		.group {
			width: 100%;

			.group-1 {
				.top {
					border: 0;
					padding: 13px 30px;
				}

				.main {
					width: 90%;
					height: 60px;
					margin: 0 auto;
					background-color: #fff;
					border-radius: 20px;
					padding: 10px;
					display: flex;
					flex-direction: row;
					justify-content: space-around;


					.txt {
						// position: absolute;
						width: 90%;
						height: 80%;
						margin: auto 0;
						color: #000000;
						border-left: 3px solid blue;
						text-indent: 1em;

						button {
							float: right;
							width: 60px;
							height: 25px;
							font-size: 16px;
							line-height: 25px;
							box-sizing: border-box;
							padding: 0;
							margin-top: 10px;
							margin-right: 10px;
							text-align: center;

						}
					}

					.time {
						height: 40%;
						display: flex;
						flex-direction: column;
					}
				}
			}
		}

		.new {
			position: fixed;
			width: 50px;
			height: 50px;
			background-color: #006afc;
			bottom: 50px;
			right: 20px;
			line-height: 45px;
			text-align: center;
			border-radius: 50%;
			color: #fff;
			font-size: 40px;
		}

		.active {
			.top {
				color: blue;
			}
		}

	}
</style>